// DataSourcePage.cpp : implementation file
//

#include "stdafx.h"
#include "txt_pqdif.h"
#include "DataSourcePage.h"
#include "helpers.h"
#include "AppStr.h"
#include "invalid_value.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

static const int NAME_BUF_LEN = 129;

/////////////////////////////////////////////////////////////////////////////
// CDataSourcePage property page

IMPLEMENT_DYNCREATE(CDataSourcePage, CPropertyPage)

CDataSourcePage::CDataSourcePage() : CPropertyPage(CDataSourcePage::IDD)
{
	//{{AFX_DATA_INIT(CDataSourcePage)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CDataSourcePage::~CDataSourcePage()
{
}

void CDataSourcePage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDataSourcePage)
	//DDX_Control(pDX, IDC_EDIT_NAME, m_edtName);
	DDX_Control(pDX, IDC_COMBO_VENDOR, m_cboVendor);
	DDX_Control(pDX, IDC_COMBO_TYPE, m_cboType);
	DDX_Control(pDX, IDC_COMBO_EQUIPMENT, m_cboEquipment);
	//}}AFX_DATA_MAP
	DDX_Control(pDX, IDC_EDIT_NAME, m_edtName);
}


BEGIN_MESSAGE_MAP(CDataSourcePage, CPropertyPage)
	//{{AFX_MSG_MAP(CDataSourcePage)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDataSourcePage message handlers

BOOL CDataSourcePage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	FillGUIDCombo (m_cboVendor, _T("ID_VENDOR_"));
	FillGUIDCombo (m_cboType, _T("ID_DS_TYPE_"));
	FillGUIDCombo (m_cboEquipment, _T("ID_EQUIP_"));

	InitInvalidDefn();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDataSourcePage::TransferFromDataSource( MCFDataSourceInfo* pDSI )
{
	CString buf_Vecdor,buf_Equipment,buf_Type;;
	APPSTR_ASCII ascii_Name(pDSI->szName);
	m_edtName.SetWindowText (ascii_Name.WCHAR_PTR());
	SelectGUIDCombo (m_cboVendor, pDSI->guidVendorID,buf_Vecdor);
	SelectGUIDCombo (m_cboEquipment, pDSI->guidEquipmentID,buf_Equipment);
	SelectGUIDCombo (m_cboType, pDSI->guidDataSourceTypeID,buf_Type);
	m_cboVendor.SetWindowText(buf_Vecdor);
	m_cboEquipment.SetWindowText(buf_Equipment);
	m_cboType.SetWindowText(buf_Type);
}

void CDataSourcePage::TransferToDataSource( MCFDataSourceInfo *pDSI )
{
	CString szName;
	m_edtName.GetWindowText (szName);
	WideCharToMultiByte( CP_OEMCP, NULL, szName, -1, 
	pDSI->szName, MCFIPQ_EXTERNNAME_LENGTH, NULL, FALSE );
	GetSelectedGUIDCombo (m_cboVendor, pDSI->guidVendorID);
	GetSelectedGUIDCombo (m_cboEquipment, pDSI->guidEquipmentID);
	GetSelectedGUIDCombo (m_cboType, pDSI->guidDataSourceTypeID);
}

void CDataSourcePage::InitInvalidDefn()
{
	invalidDataSource.guidDataSourceTypeID = ID_DS_TYPE_INVALID;
	invalidDataSource.guidVendorID = ID_VENDOR_INVALID;
	invalidDataSource.guidEquipmentID = ID_EQUIP_INVALID;

	CString nullStr(_T(""));
	SelectGUIDCombo (m_cboVendor, invalidDataSource.guidVendorID,nullStr);
	SelectGUIDCombo (m_cboEquipment, invalidDataSource.guidEquipmentID,nullStr);
	SelectGUIDCombo (m_cboType, invalidDataSource.guidDataSourceTypeID,nullStr);
}

void CDataSourcePage::ClearAllInfo()
{
	InitInvalidDefn();
	m_edtName.Clear();
}


